//
//  SISSTakeLookRecordViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/14.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSTakeLookRecordViewController.h"
#import "SISSHouseTakeLookRecordCell.h"
#import "SISSPassengerTakeLookRecordCell.h"

@interface SISSTakeLookRecordViewController ()


/* addRecordButton */
@property (weak, nonatomic) UIButton *addRecordButton;



@end

@implementation SISSTakeLookRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"看房记录";

    
}

#pragma mark - 点击添加看房记录按钮
- (void)addRecordButtonDidClick:(UIButton *)button {
    
    NSLog(@"添加看房记录");
    [self addRecordButtonDidClickAction];
}


- (void)addRecordButtonDidClickAction {
    
}


#pragma mark - UITableViewDelegate & UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuseID = @"reuseID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    if ( !cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
    }
    return cell;
}




#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    SISSBaseTableView *tableView = [[SISSBaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    // 自动行高
    tableView.estimatedRowHeight = 80;
    tableView.rowHeight = UITableViewAutomaticDimension;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableView registerClass:[SISSHouseTakeLookRecordCell class] forCellReuseIdentifier:houseTakeLookRecordCellReuseID];
    [tableView registerClass:[SISSPassengerTakeLookRecordCell class] forCellReuseIdentifier:passengerTakeLookRecordCellReuseID];
    [self.view addSubview:tableView];
    self.tableView = tableView;
    
    // 添加看房记录按钮(只有合作方才能添加带看)
    UIButton *addRecordButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addRecordButton setTitle:@"添加看房记录" forState:UIControlStateNormal];
    [addRecordButton setBackgroundColor:MAIN_COLOR];
    [addRecordButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    addRecordButton.hidden = self.type == 1; // 发布方隐藏
    if (self.isHistory) {
        addRecordButton.hidden = YES;
    }
    [addRecordButton addTarget:self action:@selector(addRecordButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addRecordButton];
    self.addRecordButton = addRecordButton;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    // 自动布局
    CGFloat margin = 10;
    WeakSelf
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view);
        make.left.right.equalTo(weakSelf.view);
        make.bottom.equalTo(weakSelf.addRecordButton.mas_top);
    }];
    
    [self.addRecordButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(4 * margin);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(weakSelf.view);
        }
    }];
}


@end
